import Vue from 'vue';

import Cookies from 'js-cookie';

import 'normalize.css/normalize.css'; // A modern alternative to CSS resets

import Element from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

import '@/styles/index.scss'; // global css

import App from './App';
import store from './store';
import router from './router';

import i18n from './lang'; // Internationalization
import './icons'; // icon
import './errorLog'; // error log
import './permission'; // permission control
import permission from '@/directive/permission/index.js'; // 权限判断指令
import './mock'; // simulation data

import VOrgTree from 'v-org-tree';
import 'v-org-tree/dist/v-org-tree.css';
import { directive as clickOutside } from 'v-click-outside-x';

import * as filters from './filters'; // global filters

import vueDateFormat from 'vue-date-format';
import AMap from 'vue-amap';
Vue.use(AMap);

// 初始化vue-amap
AMap.initAMapApiLoader({
  // 高德key
  key: '472fa899f19716a3f80e5b4bfcf54695',
  // 插件集合 （插件按需引入）
  plugin: ['AMap.Autocomplete', 'AMap.Geocoder', 'AMap.Geolocation'],
  v: '1.4.4',
  uiVersion: '1.0'
});
Vue.use(Element, {
  size: Cookies.get('size') || 'medium', // set element-ui default size
  i18n: (key, value) => i18n.t(key, value)
});
Vue.use(vueDateFormat);

// register global utility filters.
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key]);
});

Vue.config.productionTip = false;

Vue.directive('permission', permission);
Vue.directive('clickOutside', clickOutside);

Vue.use(VOrgTree);
import { fnResize } from '@/utils';
router.afterEach((to, from) => {
  if (to.path.includes('dashboard')) {
    fnResize();
  } else {
    document.documentElement.style.fontSize = 'unset';
  }
});
new Vue({
  el: '#app',
  router,
  store,
  i18n,
  render: h => h(App)
});
